-------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  /Users/Wei/Dropbox/Fertility/Results/census_data.log
  log type:  text
 opened on:  21 Jan 2020, 09:49:53

. 
. 
. use "$path1/china1990.dta",clear 

. ren birthyear year_birth

. ren relate relation 

. mvencode hhcode*, mv(9999) 
     hhcode1: 113449 missing values recoded
              (recast to int)
     hhcode2: 113449 missing values recoded
              (recast to int)
     hhcode3: 113449 missing values recoded

. egen hhid =group(province prefect  county hhcode* hh_ty hh_no)

. ren marst  maritus

. ren working ifwork

. ren chborn n_birth 

. ren chsurv n_survive

. ren ceb_m n_mbirth

. ren ceb_f n_fbirth

. ren ceb_sm n_mchild

. ren ceb_sf n_fchild

. ren hhtype hktype

. 
. ren hh_ty hhtype

. ren occu occ

. ren industry ind 

. drop county

. destring countycode,replace force 
countycode already numeric; no replace

. ren countycode county

. ren race ethnic

. egen id = group(hhid county relation)

. replace year = 1990
(0 real changes made)

. gen prov = res_85 if res_85 > 2 
(11,452,099 missing values generated)

. replace prov = province if mi(prov) 
(11,452,099 real changes made)

. keep id hhid prov county province sex ethnic hktype educ year_birth age relation  maritus marri
> ed ifwork n_birth n_survive ind occ year ///
> n_mbirth n_fbirth n_mchild n_fchild hhtype

. ren county region

. 
. su 

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
    province | 11,568,585    37.72836     13.3992         11         65
         sex | 11,568,585    1.484825    .4997697          1          2
      ethnic | 11,568,585    1.708743    3.532135          1         98
      hktype | 11,568,585    1.194066    .4151238          0          2
        educ | 11,568,585    2.053464    1.258624          0          7
-------------+---------------------------------------------------------
         ind | 11,568,585    100.1447    238.9828          0        998
         occ | 11,568,585    343.8362    326.0587          0        998
    n_mbirth | 11,568,585    .3522662    .8718554          0          9
    n_fbirth | 11,568,585    .3248567    .8539362          0          9
    n_mchild | 11,568,585    .3271293    .7993424          0          9
-------------+---------------------------------------------------------
    n_fchild | 11,568,585    .3021714    .7885871          0          9
      hhtype | 11,568,585    1.029288    .1686134          1          2
        year | 11,568,585        1990           0       1990       1990
         age | 11,568,585    28.70852    19.47863          0        120
    relation | 11,568,585    4.196374    2.787627          1         12
-------------+---------------------------------------------------------
     maritus | 11,568,585    1.633018    .7102311          1          4
     married | 11,568,585    .4926719    .4999463          0          1
      ifwork | 11,568,585    .8482993    .3587305          0          1
  year_birth | 11,568,585    1961.291    19.47863       1870       1990
     n_birth | 11,568,585    .6771229    1.532647          0         18
-------------+---------------------------------------------------------
   n_survive | 11,568,585    .6293006    1.392514          0         16
      region | 11,568,585    378751.7    134262.8     110101     659001
        hhid | 11,568,585     1372362    790386.7          1    2734379
          id | 11,568,585     3970506     2289901          1    7922844
        prov | 11,568,585    37.76215    13.38694         11         91

. 
. gen work = ifwork == 1 if !mi(ifwork)

. 
. recode educ (0/1 = 1) (2 = 2 ) ( 3= 3) (4 = 4) (5/9 = 5) 
(educ: 1567938 changes made)

. order hhid id region prov*

. save "$path2/marr_90_temp",replace 
(note: file /Users/Wei/Dropbox/Fertility/Workingdata/marr_90_temp.dta not found)
file /Users/Wei/Dropbox/Fertility/Workingdata/marr_90_temp.dta saved

. 
. 
. use "$path1/census2000_nodup.dta",clear 

. tab h02

        h02 |      Freq.     Percent        Cum.
------------+-----------------------------------
          1 | 11,350,421      100.00      100.00
------------+-----------------------------------
      Total | 11,350,421      100.00

. keep id  r01 r02 r03 r041 r042 r05 r07 r061 r062 r081 r082 /// // region info & Demographics 
> r151 r152 r16 r19 r20 r18  /// // Educaiton, SES and occupation 
> r17 r23 r241 r241 r242 r251 r252 r253 r254  /// // Mariage & fertility 
>  ra0 ra1 r06* // Hukou

.  
. gen province = real(substr(id,1,2))

. gen region = real(substr(id,1,4))

. egen hhid = group(id)

. ren r01 name 

. ren r02 relation

. ren r03 sex 

. ren r041 year_birth

. ren r042 moth_birth

. ren r05 ethnic 

. ren r07 hktype 

. ren r151 educ 

. ren r16 ifend_educ

. ren r19 ind

. ren r20 occ

. ren r23 maritus

. ren r241 year_mar1

. ren r242 month_mar1

. ren r251 n_mbirth

. ren r252 n_fbirth

. ren r253 n_mchild

. ren r254 n_fchild

. ren r17 ifwork

. ren r18 worktime

. ren ra0 city_flag

. su

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
          id |          0
        name | 11,350,421    2.501941    1.429485          1         30
    relation | 11,350,418    1.650896    1.885018          0          9
         sex | 11,350,421    1.489638    .4998926          1          2
  year_birth | 11,350,421    1967.314    19.97509       1885       2000
-------------+---------------------------------------------------------
  moth_birth | 11,350,421    6.677242    3.447732          1         12
      ethnic | 11,350,421    1.775173     3.81507          1         98
        r061 | 11,350,421    1.113275    .3862874          1          5
        r062 | 11,072,636    .5036154    1.734355          0          8
        r063 | 11,064,641    .6935032     5.38061          0         65
-------------+---------------------------------------------------------
      hktype | 11,275,255    1.241175    .4281553          0          2
        r081 | 11,350,421    1.171829    .4878746          1          3
        r082 | 11,192,513    1.765576    8.409883          0         91
        educ | 10,534,692    3.555902    1.283656          0          9
        r152 | 10,290,416    .2663129    .6601719          0          2
-------------+---------------------------------------------------------
  ifend_educ |  9,441,623     1.85116    .6180653          0          5
      ifwork |  8,597,390    1.532912    .8703487          0          3
    worktime |  6,196,187    5.821774    1.463066          0          7
         ind |  6,426,442    188.5469    290.9114          0        999
         occ |  6,426,350    514.2343     158.098          0        999
-------------+---------------------------------------------------------
     maritus |  8,609,605    2.035295    .8761261          0          5
   year_mar1 |  7,101,017    1971.524    116.2829          0       2000
  month_mar1 |  7,100,949     6.95652    3.960555          0         12
    n_mbirth |  2,622,525    .8828442    .7548657          0          9
    n_fbirth |  2,622,096    .7904398    .8300035          0          9
-------------+---------------------------------------------------------
    n_mchild |  2,620,645    .8641583    .7362307          0          9
    n_fchild |  2,620,257    .7744431    .8128265          0          9
   city_flag | 11,350,421    2.430594    .8283503          1          3
         ra1 | 11,221,069    32.89393    19.78145          1        115
    province | 11,350,421    37.70511     13.4076         11         65
-------------+---------------------------------------------------------
      region | 11,350,421    3780.477    1343.732       1101       6540
        hhid | 11,350,421     1707111      974510          1    3355042

. 
. gen prov_hk=prov

. replace prov_hk = r063 if r063 != 0 & r063 < .
(197,886 real changes made)

. *keep if $age_sample
. drop if year_mar1 < 1900 
(24,201 observations deleted)

. gen age = 2000 - year_birth 

. 
. gen husband = sex == 1 & (relation ==0 | relation ==1) // head or spouse

. gen wife = sex == 2 & (relation  ==0 | relation ==1) // head or spouse

. 
. gen married = maritus == 2 | maritus == 3 if !mi(maritus)
(2,740,787 missing values generated)

. gen age_marr1 = year_mar1 - year_birth
(4,249,404 missing values generated)

. 
. gen prov = prov_hk

. replace prov = province 
(197,388 real changes made)

. 
. gen year = 2000 

. recode educ (0/2 = 1) (3 = 2 ) ( 4= 3) (5/6 = 4) (7/9 = 5) 
(educ: 9592716 changes made)

. gen work = ifwork == 1 if !mi(ifwork)
(2,740,037 missing values generated)

. gen n_birth = n_mbirth + n_fbirth 
(8,728,192 missing values generated)

. gen n_survive = n_mchild + n_fchild 
(8,731,235 missing values generated)

. egen iid = group(id)

. drop id

. ren iid id

. save "$path2/marr_00_temp",replace 
(note: file /Users/Wei/Dropbox/Fertility/Workingdata/marr_00_temp.dta not found)
file /Users/Wei/Dropbox/Fertility/Workingdata/marr_00_temp.dta saved

. 
. 
. use "$path1/china2005",clear // 2005 census 

. keep  region hhid hhtype name relation sex year_birth moth_birth ethnic hktype nbroth nsister p
> rov_5y_res literacy health ///
> educ ifend_educ ind occ maritus year_mar1 month_mar1 n_mbirth n_fbirth n_mchild n_fchild age  c
> ity_flag income ifwork hour_w prov_hk

. 
. su 

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
      region |  2,585,481    3917.616    1494.489       1101       6590
        hhid |  2,585,481    24179.87    24625.23          0     127152
      hhtype |  2,585,481     1.02994    .1704226          1          2
        name |  2,585,481    2.673521    1.938176          1         99
    relation |  2,585,475    1.924034    2.289154          0          9
-------------+---------------------------------------------------------
         sex |  2,585,479    1.498537    .5000521          1          9
  year_birth |  2,585,481    1970.605    20.18001       1895       2005
  moth_birth |  2,585,481    6.649678    3.437535          1         12
      ethnic |  2,585,481    1.963313    4.045214          1         98
     prov_hk |  2,585,481    3.404177    11.56499          0         71
-------------+---------------------------------------------------------
      hktype |  2,571,842    1.278304    .4481657          0          2
      nbroth |  1,138,553     .637251    .7784351          0          9
     nsister |  1,138,559    .6661991    .8889348          0          9
      health |  2,585,481    1.097717    .3909057          1          4
 prov_5y_res |  2,445,782     1.54566    8.007707          0         91
-------------+---------------------------------------------------------
    literacy |  2,414,762     1.09473    .2928746          1          5
        educ |  2,414,761    2.747951     1.08337          1          7
  ifend_educ |  2,173,222    1.866238     .614964          1          5
      ifwork |  2,061,327    1.666832    .9355728          0          3
      hour_w |  2,061,321    30.41034    24.39535          0         99
-------------+---------------------------------------------------------
         ind |  1,388,168    24.06519    30.60538          1         99
         occ |  1,388,166    51.29217    17.98991          0         99
      income |  2,585,481    334.9903    681.4475          0      99999
     maritus |  2,061,319    1.998497    .8666906          1          5
   year_mar1 |  1,639,016    1981.902    15.21702       1894       2005
-------------+---------------------------------------------------------
  month_mar1 |  1,639,012    6.856249    3.939411          0         12
    n_mbirth |    744,698    1.022028    .8379709          0          9
    n_fbirth |    744,698     .901352    .9120079          0          9
    n_mchild |    744,698    1.000058    .8135807          0          9
    n_fchild |    744,697    .8839635    .8915522          0          9
-------------+---------------------------------------------------------
         age |  2,585,481    34.23252    20.18139          0        110
   city_flag |          0

. destring city_flag, replace force 
city_flag: contains nonnumeric characters; replaced as byte
(11 missing values generated)

. drop if city_flag == .
(11 observations deleted)

. 
. gen province = int(region/100)

. gen distric = region - province * 100 

. * Keep aged between 15 and 60 first 
. 
. *keep if $age_sample
. drop if year_mar1 < 1900 
(4 observations deleted)

. 
. * When look at marriage age, we may need to keep those not marred first? 
. gen married = maritus == 2 | maritus == 3 if !mi(maritus)
(524,154 missing values generated)

. gen age_marr1 = year_mar1 - year_birth
(946,460 missing values generated)

. recode educ (0/1 = 1) (2 = 2 ) ( 3= 3) (4 = 4) (5/9 = 5) 
(educ: 54839 changes made)

. 
. gen prov = province

. replace prov_hk=prov if prov_hk==0
(2,357,939 real changes made)

. 
. replace prov = prov_hk
(130,096 real changes made)

. 
. gen work = ifwork == 1 if !mi(ifwork)
(524,154 missing values generated)

. replace prov = province 
(130,096 real changes made)

. 
. ren hour_w worktime

. replace worktime=worktime/8
variable worktime was byte now float
(1,359,915 real changes made)

. gen n_birth = n_mbirth + n_fbirth 
(1,840,772 missing values generated)

. gen n_survive = n_mchild + n_fchild 
(1,840,772 missing values generated)

. gen year = 2005

. save "$path2/marr_05_temp",replace 
(note: file /Users/Wei/Dropbox/Fertility/Workingdata/marr_05_temp.dta not found)
file /Users/Wei/Dropbox/Fertility/Workingdata/marr_05_temp.dta saved

. 
. 
. use "$path2/marr_05_temp", clear 

. append using "$path2/marr_00_temp"
(note: variable ind was byte, now int to accommodate using data's values)
(note: variable occ was byte, now int to accommodate using data's values)
(note: variable region was long, now double to accommodate using data's values)
(note: variable hhid was long, now double to accommodate using data's values)
(note: variable prov_hk was byte, now float to accommodate using data's values)
(note: variable age was int, now float to accommodate using data's values)

. append using "$path2/marr_90_temp"

. 
. cap erase "$path2/marr_05_temp.dta"

. cap erase "$path2/marr_00_temp.dta"

. cap erase "$path2/marr_90_temp.dta"

. 
. drop if mi(year)
(0 observations deleted)

. drop if mi(year_birth)
(0 observations deleted)

. 
. gen wt = 1 if year == 1990 | year == 2000 
(2,585,466 missing values generated)

. replace wt = 4 if year == 2005 
(2,585,466 real changes made)

. cap drop id 

. gen male = sex == 1 

. 
. gen han = ethnic == 1 

. 
. replace age_marr1 = . if age_marr1 < 15 | age_marr1 > 60 
(15,528 real changes made, 15,528 to missing)

. replace age = year - year_birth 
(419,019 real changes made)

. 
. 
. replace hktype = 9 if hktype == 0 | mi(hktype)
(182,236 real changes made)

. *drop if hktype == 9
. 
. gen married_ever = maritus != 1 if !mi(maritus)
(3,264,941 missing values generated)

. 
. gen women = male == 0 

. gen men = male == 1 

. gen senior = educ >= 4 

. gen college = educ >= 5

. replace worktime = . if work == 0 
(711,947 real changes made, 711,947 to missing)

. gen hour_w = worktime * 8 if year == 2005 
(24,120,356 missing values generated)

. replace hour_w = worktime *8 if year == 2000 
(6,174,904 real changes made)

. 
. replace occ = int(occ/10) if year <= 2000
(13,018,555 real changes made)

. gen high_occ = occ <= 39  & occ !=0 if work == 1
(8,131,849 missing values generated)

. replace occ = 11 if occ <= 11 &  occ !=0
(360,167 real changes made)

. 
. 
. cap drop late_marr

. gen late_marr =  age_marr > 25  if !mi(age_marr)
(16,779,977 missing values generated)

. replace late_marr = married_ever == 0 if mi(age_marr)
(16,779,977 real changes made)

. *replace late_marr = . if year == 1990
. 
. cap drop divorce_ever

. gen divorce_ever= maritus == 3 | maritus == 4 if year >= 2000
(11,568,585 missing values generated)

. replace divorce_ever = maritus == 4 if year == 1990
(11,568,585 real changes made)

. replace divorce_ever = . if married_ever == 0 
(7,241,805 real changes made, 7,241,805 to missing)

. 
. gen hlth = health == 1 if !mi(health)
(22,894,805 missing values generated)

. gen chd_death = n_birth - n_survive >= 1  if !mi(n_birth) & !mi(n_survive) & !(n_birth < n_surv
> ive) & n_birth >=1 & women == 1 
(19,667,311 missing values generated)

. gen boy_death = n_mbirth - n_mchild >= 1  if !mi(n_birth) & !mi(n_survive) & !(n_birth < n_surv
> ive) & !mi(n_mbirth) & n_mbirth >= 1  & women == 1 
(20,926,415 missing values generated)

. gen girl_death = n_fbirth - n_fchild >= 1  if !mi(n_birth) & !mi(n_survive) & !(n_birth < n_sur
> vive) & !mi(n_fbirth) & n_fbirth >= 1  & women == 1 
(21,445,405 missing values generated)

. 
. su late_marr married_ever 

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
   late_marr | 25,480,271    .3465646    .4758756          0          1
married_ever | 22,215,330    .6740177    .4687407          0          1

. gen sur_rate= n_survive/n_birth *100
(19,667,310 missing values generated)

. replace sur_rate = . if sur_rate > 100 
(1 real change made, 1 to missing)

. replace sur_rate = 0 if women == 0 
(13,036,691 real changes made)

. gen sur_boy = n_mchild/n_mbirth * 100
(20,924,485 missing values generated)

. gen sur_girl = n_fchild/n_fbirth * 100
(21,443,853 missing values generated)

. 
. gen n_birth_gender = n_mbirth - n_fbirth
(10,568,964 missing values generated)

. gen n_child_gender = n_mchild - n_fchild
(10,572,007 missing values generated)

.  
. keep if year_birth >= 1940 & year_birth <= 1980 & age >= 25
(13,932,473 observations deleted)

. ren year year_temp

. 
. forvalues ag = 0(1)39{
  2. g year = year_birth + `ag' 
  3. merge m:1 prov year using "$path2/fines_use", keepusing(fine) nogen
  4. replace fine = 0 if year < 1979
  5. ren fine fine_age`ag'
  6. drop year
  7. }
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                    11,479,039
        from master                11,478,264  
        from using                        775  

    matched                            69,534  
    -----------------------------------------
(11,478,264 real changes made)
(775 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                    11,444,074
        from master                11,443,330  
        from using                        744  

    matched                           105,243  
    -----------------------------------------
(11,442,555 real changes made)
(1,519 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                    11,411,369
        from master                11,410,656  
        from using                        713  

    matched                           138,661  
    -----------------------------------------
(11,409,137 real changes made)
(2,232 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                    11,374,799
        from master                11,374,117  
        from using                        682  

    matched                           175,913  
    -----------------------------------------
(11,371,885 real changes made)
(2,914 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                    11,163,695
        from master                11,163,044  
        from using                        651  

    matched                           387,668  
    -----------------------------------------
(11,160,130 real changes made)
(3,565 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                    10,935,447
        from master                10,934,827  
        from using                        620  

    matched                           616,536  
    -----------------------------------------
(10,931,262 real changes made)
(4,185 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                    10,694,370
        from master                10,693,781  
        from using                        589  

    matched                           858,202  
    -----------------------------------------
(10,689,596 real changes made)
(4,774 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                    10,430,630
        from master                10,430,072  
        from using                        558  

    matched                         1,122,500  
    -----------------------------------------
(10,425,298 real changes made)
(5,332 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                    10,164,840
        from master                10,164,313  
        from using                        527  

    matched                         1,388,817  
    -----------------------------------------
(10,158,981 real changes made)
(5,859 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                     9,867,312
        from master                 9,866,816  
        from using                        496  

    matched                         1,686,841  
    -----------------------------------------
(9,860,957 real changes made)
(6,355 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                     9,596,726
        from master                 9,596,261  
        from using                        465  

    matched                         1,957,892  
    -----------------------------------------
(9,589,906 real changes made)
(6,820 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                     9,286,769
        from master                 9,286,335  
        from using                        434  

    matched                         2,268,283  
    -----------------------------------------
(9,279,515 real changes made)
(7,254 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                     9,043,001
        from master                 9,042,598  
        from using                        403  

    matched                         2,512,454  
    -----------------------------------------
(9,035,344 real changes made)
(7,657 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                     8,770,461
        from master                 8,770,089  
        from using                        372  

    matched                         2,785,366  
    -----------------------------------------
(8,762,432 real changes made)
(8,029 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                     8,244,301
        from master                 8,243,960  
        from using                        341  

    matched                         3,311,867  
    -----------------------------------------
(8,235,919 real changes made)
(8,370 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                     7,724,629
        from master                 7,724,319  
        from using                        310  

    matched                         3,831,849  
    -----------------------------------------
(7,715,927 real changes made)
(8,680 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                     7,121,053
        from master                 7,120,774  
        from using                        279  

    matched                         4,435,704  
    -----------------------------------------
(7,112,063 real changes made)
(8,959 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                     6,628,169
        from master                 6,627,921  
        from using                        248  

    matched                         4,928,836  
    -----------------------------------------
(6,618,916 real changes made)
(9,207 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                     6,370,027
        from master                 6,369,810  
        from using                        217  

    matched                         5,187,195  
    -----------------------------------------
(6,360,541 real changes made)
(9,424 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                     6,070,028
        from master                 6,069,842  
        from using                        186  

    matched                         5,487,380  
    -----------------------------------------
(6,060,351 real changes made)
(9,610 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                     5,784,989
        from master                 5,784,834  
        from using                        155  

    matched                         5,772,574  
    -----------------------------------------
(5,775,145 real changes made)
(9,765 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                     5,416,132
        from master                 5,416,008  
        from using                        124  

    matched                         6,141,555  
    -----------------------------------------
(5,406,154 real changes made)
(9,889 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                     4,999,171
        from master                 4,999,078  
        from using                         93  

    matched                         6,558,609  
    -----------------------------------------
(4,989,089 real changes made)
(9,982 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                     4,608,390
        from master                 4,608,328  
        from using                         62  

    matched                         6,949,452  
    -----------------------------------------
(4,598,231 real changes made)
(10,044 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                     4,202,470
        from master                 4,202,439  
        from using                         31  

    matched                         7,355,403  
    -----------------------------------------
(4,192,270 real changes made)
(10,075 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                     3,788,129
        from master                 3,788,129  
        from using                          0  

    matched                         7,769,744  
    -----------------------------------------
(3,777,920 real changes made)
(10,075 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                     3,440,885
        from master                 3,440,885  
        from using                          0  

    matched                         8,116,988  
    -----------------------------------------
(3,396,325 real changes made)
(10,075 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                     3,087,989
        from master                 3,087,989  
        from using                          0  

    matched                         8,469,884  
    -----------------------------------------
(3,008,234 real changes made)
(10,075 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                     2,800,542
        from master                 2,800,542  
        from using                          0  

    matched                         8,757,331  
    -----------------------------------------
(2,685,066 real changes made)
(10,075 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                     2,515,218
        from master                 2,515,218  
        from using                          0  

    matched                         9,042,655  
    -----------------------------------------
(2,366,313 real changes made)
(10,075 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                     2,232,833
        from master                 2,232,833  
        from using                          0  

    matched                         9,325,040  
    -----------------------------------------
(2,046,674 real changes made)
(10,075 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                     2,173,078
        from master                 2,173,078  
        from using                          0  

    matched                         9,384,795  
    -----------------------------------------
(1,775,158 real changes made)
(10,075 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                     2,135,110
        from master                 2,135,110  
        from using                          0  

    matched                         9,422,763  
    -----------------------------------------
(1,508,319 real changes made)
(10,075 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                     2,131,499
        from master                 2,131,499  
        from using                          0  

    matched                         9,426,374  
    -----------------------------------------
(1,263,028 real changes made)
(10,075 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                     2,167,631
        from master                 2,167,631  
        from using                          0  

    matched                         9,390,242  
    -----------------------------------------
(1,034,855 real changes made)
(10,075 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                     2,212,403
        from master                 2,212,403  
        from using                          0  

    matched                         9,345,470  
    -----------------------------------------
(813,298 real changes made)
(10,075 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                     2,312,048
        from master                 2,312,048  
        from using                          0  

    matched                         9,245,825  
    -----------------------------------------
(614,917 real changes made)
(10,075 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                     2,378,605
        from master                 2,378,605  
        from using                          0  

    matched                         9,179,268  
    -----------------------------------------
(410,415 real changes made)
(10,075 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                     2,484,214
        from master                 2,484,214  
        from using                          0  

    matched                         9,073,659  
    -----------------------------------------
(205,629 real changes made)
(10,075 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                     2,522,761
        from master                 2,522,761  
        from using                          0  

    matched                         9,035,112  
    -----------------------------------------
(0 real changes made)

. 
. forvalues ag = 1(1)3{
  2. g year = year_birth - `ag' 
  3. merge m:1 prov year using "$path2/fines_use", keepusing(fine) nogen
  4. replace fine = 0 if year < 1979
  5. ren fine fine_f`ag'
  6. drop year
  7. }
(10,075 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                    11,524,331
        from master                11,523,525  
        from using                        806  

    matched                            34,348  
    -----------------------------------------
(11,513,450 real changes made)
(10,881 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                    11,559,516
        from master                11,558,679  
        from using                        837  

    matched                                 0  
    -----------------------------------------
(11,547,798 real changes made)
(11,718 missing values generated)
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                    11,560,353
        from master                11,559,516  
        from using                        837  

    matched                                 0  
    -----------------------------------------
(11,547,798 real changes made)

. 
.  
. ren year_temp year

. 
. egen fine_f2_5 = rowmean(fine_f2 fine_f1 fine_age0 fine_age1-fine_age5)
(6727 missing values generated)

. egen fine_6_10 = rowmean(fine_age6-fine_age10)
(9920 missing values generated)

. egen fine_11_15 = rowmean(fine_age11-fine_age15)
(10695 missing values generated)

. egen fine_16_20 = rowmean(fine_age16-fine_age20)
(11501 missing values generated)

. egen fine_21_25 = rowmean(fine_age21-fine_age25)
(12334 missing values generated)

. 
. egen fine_6_12 = rowmean(fine_age6-fine_age12)
(9083 missing values generated)

. egen fine_13_19 = rowmean(fine_age13-fine_age19)
(10602 missing values generated)

. egen fine_20_25 = rowmean(fine_age20-fine_age25)
(12169 missing values generated)

. 
. egen fine_6_15 = rowmean(fine_age6-fine_age15)
(8060 missing values generated)

. egen fine_16_25 = rowmean(fine_age16-fine_age25)
(11191 missing values generated)

. 
. drop if mi(fine_21_25)
(12,334 observations deleted)

. replace year = int(year)
(0 real changes made)

. drop if mi(wt)
(310 observations deleted)

. drop if prov > 70 
(143 observations deleted)

. replace prov_hk = prov if mi(prov_hk)
(4,140,908 real changes made)

. drop if prov_hk >= 70 
(0 observations deleted)

. 
. compress
  variable prov_hk was float now byte
  variable occ was int now byte
  variable age was float now byte
  variable province was float now byte
  variable distric was float now byte
  variable married was float now byte
  variable age_marr1 was float now byte
  variable prov was float now byte
  variable work was float now byte
  variable n_birth was float now byte
  variable n_survive was float now byte
  variable year was float now int
  variable ra1 was int now byte
  variable husband was float now byte
  variable wife was float now byte
  variable wt was float now byte
  variable male was float now byte
  variable han was float now byte
  variable married_ever was float now byte
  variable women was float now byte
  variable men was float now byte
  variable senior was float now byte
  variable college was float now byte
  variable hour_w was float now byte
  variable high_occ was float now byte
  variable late_marr was float now byte
  variable divorce_ever was float now byte
  variable hlth was float now byte
  variable chd_death was float now byte
  variable boy_death was float now byte
  variable girl_death was float now byte
  variable n_birth_gender was float now byte
  variable n_child_gender was float now byte
  variable fine_f2 was float now byte
  variable fine_f3 was float now byte
  variable region was double now long
  variable hhid was double now long
  (1,247,137,128 bytes saved)

. save "$path2/marr_policy",replace 
file /Users/Wei/Dropbox/Fertility/Workingdata/marr_policy.dta saved

. 
. ******** Child  Mortality data **** 
. 
. set more off

. 
. use "$path2/marr_policy", clear

. su

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
      region | 11,547,566    135961.2    194519.4       1101     659001
        hhid | 11,547,566     1339665      995336          0    3355042
      hhtype |  5,606,277    1.031561    .1748269          1          2
        name |  7,406,658    1.798141    1.100425          1         99
    relation | 11,547,564     1.54223    2.115718          0         12
-------------+---------------------------------------------------------
         sex | 11,547,566     1.49091    .4999174          1          2
  year_birth | 11,547,566    1958.431      9.5453       1940       1980
  moth_birth |  7,406,658    6.654044    3.436611          1         12
      ethnic | 11,547,566    1.687038    3.456195          1         98
     prov_hk | 11,547,566    37.45103    13.63283         11         65
-------------+---------------------------------------------------------
      hktype | 11,547,566    1.280093    .5326664          1          9
      nbroth |    222,267    .9424296    .9265187          0          9
     nsister |    222,267    .9480805    1.045144          0          9
      health |  1,465,369    1.065086    .3120291          1          4
 prov_5y_res |  1,465,369    1.434082    7.730473          0         91
-------------+---------------------------------------------------------
    literacy |  1,465,369    1.081031    .2728825          1          2
        educ | 11,547,566    2.683715    .9968384          1          5
  ifend_educ |  6,849,026    2.098233    .4217347          0          5
      ifwork | 11,547,566      1.1929    .6304848          0          3
    worktime |  6,060,594    5.837229    1.446992       .125     12.375
-------------+---------------------------------------------------------
         ind | 10,411,625    177.2589     289.508          0        999
         occ | 10,411,611    53.07497    19.51501          0         99
      income |  1,465,369    511.1104    819.6276          0      99999
     maritus | 11,547,566     2.03186    .4943656          1          5
   year_mar1 |  7,039,254    1983.299    10.28078       1900       2005
-------------+---------------------------------------------------------
  month_mar1 |  7,039,258     6.93802    3.985921          0         12
    n_mbirth |  7,270,116    .7532132    .8868726          0          9
    n_fbirth |  7,269,784    .6826787    .9243231          0          9
    n_mchild |  7,268,472    .7275215    .8479897          0          9
    n_fchild |  7,268,112    .6601033    .8888834          0          9
-------------+---------------------------------------------------------
         age | 11,547,566    38.61788    9.374854         25         65
   city_flag |  7,406,658    2.334201    .8640655          1          3
    province | 11,547,566    37.37787    13.67701         11         65
     distric |  1,465,369    9.537054    12.62857          1         90
     married | 11,547,566    .9187522    .2732153          0          1
-------------+---------------------------------------------------------
   age_marr1 |  7,034,405     23.0619    3.453157         15         60
        prov | 11,547,566    37.38642    13.67364         11         65
        work | 11,547,566    .8611446    .3457956          0          1
     n_birth |  7,269,258    1.435851    1.420162          0         18
   n_survive |  7,266,430    1.387465    1.342897          0         14
-------------+---------------------------------------------------------
        year | 11,547,566    1997.049    5.506441       1990       2005
        r061 |  5,941,289    1.113071    .3466363          1          5
        r062 |  5,799,940    .5935939    1.874469          0          8
        r063 |  5,795,226    .8540466    5.964223          0         65
        r081 |  5,941,289    1.218904    .5386973          1          3
-------------+---------------------------------------------------------
        r082 |  5,858,569    2.231422    9.461083          0         91
        r152 |  5,814,947     .333444    .7189599          0          2
         ra1 |  5,941,289    39.65538    9.686879         24         60
     husband |  5,941,289    .4241043    .4942063          0          1
        wife |  5,941,289    .4282601    .4948267          0          1
-------------+---------------------------------------------------------
          wt | 11,547,566    1.380696    .9985778          1          4
        male | 11,547,566    .5090896    .4999174          0          1
         han | 11,547,566    .9218586     .268394          0          1
married_ever | 11,547,566    .9474176    .2231984          0          1
       women | 11,547,566    .4909104    .4999174          0          1
-------------+---------------------------------------------------------
         men | 11,547,566    .5090896    .4999174          0          1
      senior | 11,547,566    .1817903    .3856716          0          1
     college | 11,547,566    .0518185    .2216603          0          1
      hour_w |  6,060,594    46.69783    11.57594          1         99
    high_occ |  9,944,124    .1184704    .3231643          0          1
-------------+---------------------------------------------------------
   late_marr | 11,547,566    .1692471      .37497          0          1
divorce_ever | 10,940,367      .02912    .1681428          0          1
        hlth |  1,465,369    .9512744    .2152939          0          1
   chd_death |  4,902,040    .0533109    .2246527          0          1
   boy_death |  3,814,460     .041036    .1983734          0          1
-------------+---------------------------------------------------------
  girl_death |  3,335,387    .0414321    .1992874          0          1
    sur_rate | 10,780,786     44.5502    49.21734          0        100
     sur_boy |  3,816,313    97.69586    12.30612          0        100
    sur_girl |  3,336,868    97.64432    12.63353          0        100
n_birth_ge~r |  7,269,258    .0705489    1.124719         -9          9
-------------+---------------------------------------------------------
n_child_ge~r |  7,266,430    .0674165    1.102437         -9          9
   fine_age0 | 11,547,566    .0071704    .0927928          0      1.229
   fine_age1 | 11,547,566    .0107977    .1135726          0   1.357771
   fine_age2 | 11,547,566    .0137508    .1268753          0   1.357771
   fine_age3 | 11,547,566    .0170835    .1404249          0   1.357771
-------------+---------------------------------------------------------
   fine_age4 | 11,547,566    .0379711    .2079665          0   1.357771
   fine_age5 | 11,547,566    .0606105    .2603431          0   1.357771
   fine_age6 | 11,547,566     .084196    .3037229          0   1.617998
   fine_age7 | 11,547,566    .1080132    .3383482          0   1.617998
   fine_age8 | 11,547,566    .1317516    .3678557          0   1.617998
-------------+---------------------------------------------------------
   fine_age9 | 11,547,566    .1577732    .3966276          0        2.5
  fine_age10 | 11,547,566     .181815    .4216157          0   3.631875
  fine_age11 | 11,547,566    .2102219    .4515625          0          5
  fine_age12 | 11,547,566    .2344095    .4813443          0          5
  fine_age13 | 11,547,566    .2616579     .510771          0          5
-------------+---------------------------------------------------------
  fine_age14 | 11,547,566    .3173489    .5585138          0          5
  fine_age15 | 11,547,566     .378311    .6079585          0          5
  fine_age16 | 11,547,566    .4515191    .6602964          0          5
  fine_age17 | 11,547,566    .5164529    .7123114          0          5
  fine_age18 | 11,547,566    .5593249    .7588172          0          5
-------------+---------------------------------------------------------
  fine_age19 | 11,547,566    .6086095    .8103262          0          5
  fine_age20 | 11,547,566    .6586607    .8587593          0          5
  fine_age21 | 11,547,566     .719868    .9027448          0          5
  fine_age22 | 11,547,566    .7910123    .9435864          0          5
  fine_age23 | 11,547,566    .8613708    .9815629          0          5
-------------+---------------------------------------------------------
  fine_age24 | 11,547,566    .9379035    1.016636          0          5
  fine_age25 | 11,547,566    1.017583     1.04573          0          5
  fine_age26 | 11,513,218    1.095703    1.073663          0          5
  fine_age27 | 11,478,032    1.181197     1.10377          0          5
  fine_age28 | 11,442,323     1.25543     1.13225          0          5
-------------+---------------------------------------------------------
  fine_age29 | 11,408,905    1.331243    1.161005          0          5
  fine_age30 | 11,371,653    1.399448    1.177868          0          5
  fine_age31 | 11,159,898    1.443549    1.180512          0          5
  fine_age32 | 10,931,030     1.49584    1.184688          0          5
  fine_age33 | 10,689,364    1.550345    1.186736          0          5
-------------+---------------------------------------------------------
  fine_age34 | 10,425,066    1.608298    1.190308          0          5
  fine_age35 | 10,158,749     1.66688      1.1911          0          5
  fine_age36 |  9,860,725    1.720806    1.191041          0          5
  fine_age37 |  9,589,674    1.777575    1.185189          0          5
  fine_age38 |  9,279,283    1.833072     1.17461          0          5
-------------+---------------------------------------------------------
  fine_age39 |  9,035,112    1.894388    1.160768         .1          5
     fine_f1 | 11,547,566    .0035496    .0654459          0      1.229
     fine_f2 | 11,547,566           0           0          0          0
     fine_f3 | 11,547,566           0           0          0          0
   fine_f2_5 | 11,547,566    .0188667    .0988823          0   1.075375
-------------+---------------------------------------------------------
   fine_6_10 | 11,547,566    .1327098    .3277496          0   1.726375
  fine_11_15 | 11,547,566    .2803898    .4739223          0          5
  fine_16_20 | 11,547,566    .5589134    .7076271          0          5
  fine_21_25 | 11,547,566    .8655474    .9234977          0          5
   fine_6_12 | 11,547,566    .1583115     .343428          0   2.248303
-------------+---------------------------------------------------------
  fine_13_19 | 11,547,566    .4418892    .5865363          0          5
  fine_20_25 | 11,547,566    .8310663    .8943192          0          5
   fine_6_15 | 11,547,566    .2065498     .373082          0     2.8236
  fine_16_25 | 11,547,566    .7122304    .7768622          0          5

. gen mort_rate = 100 -sur_rate if women == 1 
(6,645,526 missing values generated)

. 
. 
. egen fine_6_20 = rowmean(fine_age6-fine_age20)

. 
. gl FINE_ALL = "fine_6_15 fine_16_20 fine_21_25 fine_26_30"

. gl FINE_VAR_4 =  "fine_6_15 fine_16_20 fine_21_30"

. 
. gl FINE_VAR_3 =  "fine_6_15 fine_16_20 fine_21_25"

. gl FINE_VAR_1 = "fine_6_20"

. 
. egen han_p = mean(han), by(year hhid prov region)

. cap egen fine_6_15 = rowmean(fine_age6-fine_age15)

. cap egen fine_16_20 = rowmean(fine_age16-fine_age20)

. cap egen fine_21_25 = rowmean(fine_age21-fine_age25)

. egen fine_6_18 = rowmean(fine_age6-fine_age18)

. egen fine_6_22 = rowmean(fine_age6-fine_age22)

. egen fine_8_20 = rowmean(fine_age8-fine_age20)

. egen fine_4_20 = rowmean(fine_age4-fine_age20)

. egen fine_1_20 = rowmean(fine_age1-fine_age20)

. 
. egen fine_4_22 = rowmean(fine_age4-fine_age22)

. set more off 

. replace high_occ = 0 if high_occ == . & !mi(work)
(1,603,442 real changes made)

. 
. 
. drop if han_p >0 & han_p < 1 // drop mixed households
(325,664 observations deleted)

. drop if women == 0 
(5,705,234 observations deleted)

. set more off

. gen n_death = n_birth - n_survive
(567,307 missing values generated)

. replace n_death = . if n_death < 0
(1 real change made, 1 to missing)

. replace n_birth = 0 if married_ever == 0 
(70,329 real changes made)

. replace n_mbirth = 0 if married_ever == 0  
(70,244 real changes made)

. replace n_fbirth = 0 if married_ever == 0  
(70,225 real changes made)

. replace n_survive = 0 if married_ever == 0 
(70,299 real changes made)

. replace n_mchild = 0 if married_ever == 0 
(70,225 real changes made)

. replace n_fchild = 0 if married_ever == 0 
(70,204 real changes made)

. 
. drop if mi(n_birth)
(494,417 observations deleted)

. drop if mi(n_death)
(72,891 observations deleted)

. 
. drop if n_birth != n_mbirth + n_fbirth
(0 observations deleted)

. drop if n_mchild > n_mbirth | n_fchild > n_fbirth
(0 observations deleted)

. 
. drop if n_birth == 0 // no children 
(179,243 observations deleted)

. gen urban_hk = hktype == 2

. keep prov year year_birth n_mbirth n_fbirth n_mchild n_fchild fine_1_20 fine_6_20 fine_6_18 fin
> e_6_15 ///
> fine_6_22 fine_16_20 fine_8_20 fine_4_20 fine_4_22 fine_21_25 nbroth nsister han_p urban_hk

. gen hhid = _n 

.  
.  preserve 

. keep if n_mbirth + n_fbirth <= 5
(92,611 observations deleted)

. forvalues i = 1(1)5{
  2. gen child`i' = .
  3. }
(4,677,506 missing values generated)
(4,677,506 missing values generated)
(4,677,506 missing values generated)
(4,677,506 missing values generated)
(4,677,506 missing values generated)

. reshape long child, i(hhid prov year year_birth n_mbirth n_fbirth n_mchild n_fchild) j(order)
(note: j = 1 2 3 4 5)

Data                               wide   ->   long
-----------------------------------------------------------------------------
Number of obs.                  4.7e+06   -> 2.3e+07
Number of variables                  27   ->      24
j variable (5 values)                     ->   order
xij variables:
               child1 child2 ... child5   ->   child
-----------------------------------------------------------------------------

. gen cut1 = n_mchild 

. gen cut2 = n_mbirth 

. gen cut3 = n_mbirth+n_fchild

. gen cut4 = n_mbirth+n_fbirth

. drop if order > cut4 
(13,827,250 observations deleted)

. gen boy = . 
(9,560,280 missing values generated)

. gen die = . 
(9,560,280 missing values generated)

. replace boy = 1 if order <= cut2 
(5,057,250 real changes made)

. replace die = 0 if order <= cut1 
(4,923,759 real changes made)

. replace die = 1 if order > cut1 & order <= cut2 
(133,491 real changes made)

. replace boy = 0 if order > cut2 & order <= cut4 
(4,503,030 real changes made)

. replace die = 0 if order > cut2 & order <= cut3 
(4,388,157 real changes made)

. replace die = 1 if order > cut3 & order <= cut4
(114,873 real changes made)

. save "$path2/temp_child_1",replace 
(note: file /Users/Wei/Dropbox/Fertility/Workingdata/temp_child_1.dta not found)
file /Users/Wei/Dropbox/Fertility/Workingdata/temp_child_1.dta saved

. restore 

. 
.  preserve 

. keep if n_mbirth + n_fbirth > 5
(4,677,506 observations deleted)

. forvalues i = 1(1)18{
  2. gen child`i' = .
  3. }
(92,611 missing values generated)
(92,611 missing values generated)
(92,611 missing values generated)
(92,611 missing values generated)
(92,611 missing values generated)
(92,611 missing values generated)
(92,611 missing values generated)
(92,611 missing values generated)
(92,611 missing values generated)
(92,611 missing values generated)
(92,611 missing values generated)
(92,611 missing values generated)
(92,611 missing values generated)
(92,611 missing values generated)
(92,611 missing values generated)
(92,611 missing values generated)
(92,611 missing values generated)
(92,611 missing values generated)

. reshape long child, i(hhid prov year year_birth n_mbirth n_fbirth n_mchild n_fchild) j(order)
(note: j = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18)

Data                               wide   ->   long
-----------------------------------------------------------------------------
Number of obs.                    92611   -> 1.7e+06
Number of variables                  40   ->      24
j variable (18 values)                    ->   order
xij variables:
              child1 child2 ... child18   ->   child
-----------------------------------------------------------------------------

. gen cut1 = n_mchild 

. gen cut2 = n_mbirth 

. gen cut3 = n_mbirth+n_fchild

. gen cut4 = n_mbirth+n_fbirth

. drop if order > cut4 
(1,052,078 observations deleted)

. gen boy = . 
(614,920 missing values generated)

. gen die = . 
(614,920 missing values generated)

. replace boy = 1 if order <= cut2 
(281,609 real changes made)

. replace die = 0 if order <= cut1 
(232,598 real changes made)

. replace die = 1 if order > cut1 & order <= cut2 
(49,011 real changes made)

. replace boy = 0 if order > cut2 & order <= cut4 
(333,311 real changes made)

. replace die = 0 if order > cut2 & order <= cut3 
(287,733 real changes made)

. replace die = 1 if order > cut3 & order <= cut4
(45,578 real changes made)

. save "$path2/temp_child_2",replace 
(note: file /Users/Wei/Dropbox/Fertility/Workingdata/temp_child_2.dta not found)
file /Users/Wei/Dropbox/Fertility/Workingdata/temp_child_2.dta saved

. restore 

. use "$path2/temp_child_1", clear 

. append using "$path2/temp_child_2"

. drop n_mbirth-n_fchild order child-cut4

. save "$path2/child_gender_mort",replace 
file /Users/Wei/Dropbox/Fertility/Workingdata/child_gender_mort.dta saved

. cap erase "$path2/temp_child_1.dta"

. cap erase "$path2/temp_child_2.dta"

. 
. 
. 
. use "$path2/raw_data", clear 

. su 

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
        hhid |  6,142,841     1414215    885185.5          1    3354984
         sex |  6,142,841    1.473133    .4992777          1          2
         age |  6,142,841    7.671176    4.682715          0         17
        educ |  3,914,706    2.130659    .6222013          1          4
       rural |  6,142,841    .7516102    .4320791          0          1
-------------+---------------------------------------------------------
        prov |  6,142,841    37.61637    13.38798         11         65
   child_num |  6,142,841    2.325527    1.111024          1         11
     h_f_age |  5,626,379    34.69998    5.818929         15         99
     h_m_age |  6,142,841    32.67596    5.262222         16         64
 m_birth_age |  6,142,841    23.18848    2.951814         16         50
-------------+---------------------------------------------------------
     h_f_edu |  5,853,600    6.427012    18.62092          1         99
     h_m_edu |  6,142,841    2.252255    .9142272          1          4
     h_f_han |  5,626,379    .9248111    .2636959          0          1
     h_m_han |  6,142,841     .924014    .2649758          0          1
    h_fm_min |  6,142,841    .0688673    .2532284          0          1
-------------+---------------------------------------------------------
       twins |  6,142,841    .0113534    .1059457          0          1
       order |  6,142,841    1.655376    .8756621          1         11
        year |  6,142,841    1991.561    7.506972       1982       2005
      hktype |  4,392,145    1.161602    .3956807          0          2
 urban_hukou |  4,425,428    .1708456    .3763741          0          1
-------------+---------------------------------------------------------
  resid_type |  4,425,428    2.564525    .7241032          1          3
  birth_year |  6,142,841    1983.634     8.00503       1965       2005
 birth_month |  4,425,428    6.751767    3.507286          1         12
 h_year_mar1 |  2,213,503    1988.538    7.659417         19       2005
h_month_mar1 |  2,213,503    6.989881    4.046014          1         12
-------------+---------------------------------------------------------
    province |  6,142,841     37.6199    13.38724         11         65
      fine_1 |  4,129,580    1.326548     .781216         .1          5
      fine_2 |  3,893,364    1.291581    .7449249         .1          5
        fine |  4,375,436    1.370105    .8159686         .1          5
        male |  6,142,841    .5268673    .4992777          0          1
-------------+---------------------------------------------------------
       urban |  6,142,841    .2483898    .4320791          0          1
    fineXhan |  4,129,580    1.211087    .8059032          0          5
    h_fm_han |  6,142,841    .9311327    .2532284          0          1
 twinsXorder |     69,742    1.728471    .8751442          1          8
     time_y1 |  2,213,503    1.465319    6.062593        -16       1981
-------------+---------------------------------------------------------
     time_y2 |  4,642,471    2.893557    1.748491          0         18
     time_m1 |  2,213,503   -.1227457    5.119595        -11         11
     time_m2 |  3,130,021   -.3169547    4.829778        -11         11
      time_1 |  2,213,503    17.46109    72.65049       -193      23773
      time_2 |  3,130,021     36.1593    22.88541          1        212

. drop fine* time*

. ren prov prov_temp

. gen prov = province

. gen m_birth_year = year - h_m_age

. tab m_birth_year

m_birth_yea |
          r |      Freq.     Percent        Cum.
------------+-----------------------------------
       1918 |         14        0.00        0.00
       1919 |         12        0.00        0.00
       1920 |         21        0.00        0.00
       1921 |         39        0.00        0.00
       1922 |         56        0.00        0.00
       1923 |         81        0.00        0.00
       1924 |        115        0.00        0.01
       1925 |        110        0.00        0.01
       1926 |        185        0.00        0.01
       1927 |        215        0.00        0.01
       1928 |        288        0.00        0.02
       1929 |        337        0.01        0.02
       1930 |        509        0.01        0.03
       1931 |        605        0.01        0.04
       1932 |      1,024        0.02        0.06
       1933 |      1,149        0.02        0.08
       1934 |      1,828        0.03        0.11
       1935 |      2,575        0.04        0.15
       1936 |      3,781        0.06        0.21
       1937 |      5,531        0.09        0.30
       1938 |      8,245        0.13        0.43
       1939 |     11,946        0.19        0.63
       1940 |     17,631        0.29        0.92
       1941 |     26,554        0.43        1.35
       1942 |     37,525        0.61        1.96
       1943 |     49,158        0.80        2.76
       1944 |     68,020        1.11        3.87
       1945 |     91,003        1.48        5.35
       1946 |    112,951        1.84        7.19
       1947 |    132,443        2.16        9.34
       1948 |    143,746        2.34       11.68
       1949 |    159,354        2.59       14.28
       1950 |    199,493        3.25       17.53
       1951 |    207,382        3.38       20.90
       1952 |    255,384        4.16       25.06
       1953 |    264,433        4.30       29.36
       1954 |    273,886        4.46       33.82
       1955 |    272,967        4.44       38.27
       1956 |    235,976        3.84       42.11
       1957 |    234,208        3.81       45.92
       1958 |    224,771        3.66       49.58
       1959 |    167,586        2.73       52.31
       1960 |    173,203        2.82       55.13
       1961 |    141,545        2.30       57.43
       1962 |    230,463        3.75       61.18
       1963 |    333,353        5.43       66.61
       1964 |    287,417        4.68       71.29
       1965 |    270,378        4.40       75.69
       1966 |    250,338        4.08       79.76
       1967 |    199,589        3.25       83.01
       1968 |    206,015        3.35       86.37
       1969 |    165,126        2.69       89.06
       1970 |    152,127        2.48       91.53
       1971 |    120,069        1.95       93.49
       1972 |    102,245        1.66       95.15
       1973 |     83,784        1.36       96.52
       1974 |     67,958        1.11       97.62
       1975 |     49,300        0.80       98.42
       1976 |     35,970        0.59       99.01
       1977 |     22,253        0.36       99.37
       1978 |     15,511        0.25       99.62
       1979 |      9,725        0.16       99.78
       1980 |      5,484        0.09       99.87
       1981 |      3,277        0.05       99.93
       1982 |      2,353        0.04       99.96
       1983 |      1,192        0.02       99.98
       1984 |        598        0.01       99.99
       1985 |        301        0.00      100.00
       1986 |         79        0.00      100.00
       1987 |         42        0.00      100.00
       1988 |          6        0.00      100.00
       1989 |          3        0.00      100.00
------------+-----------------------------------
      Total |  6,142,841      100.00

. keep if m_birth_year >= 1940 & m_birth_year <= 1980
(46,517 observations deleted)

. ren year year_temp

. egen max_order = max(order), by(hhid year prov urban)

. egen max_age = max(age), by(hhid year prov urban)

. qui:{

. egen fine_6_20 = rowmean(fine_age6-fine_age20)
(7128 missing values generated)

. egen fine_6_15 = rowmean(fine_age6-fine_age15)
(8313 missing values generated)

. egen fine_16_20 = rowmean(fine_age16-fine_age20)
(11748 missing values generated)

. egen fine_21_25 = rowmean(fine_age21-fine_age25)
(12498 missing values generated)

. egen fine_6_18 = rowmean(fine_age6-fine_age18)
(7512 missing values generated)

. egen fine_6_22 = rowmean(fine_age6-fine_age22)
(6864 missing values generated)

. egen fine_8_20 = rowmean(fine_age8-fine_age20)
(8292 missing values generated)

. egen fine_4_20 = rowmean(fine_age4-fine_age20)
(5844 missing values generated)

. egen fine_1_20 = rowmean(fine_age1-fine_age20)
(3693 missing values generated)

. 
. egen fine_4_22 = rowmean(fine_age4-fine_age22)
(5580 missing values generated)

. 
. ren year_temp year

. 
. ren birth_year by_temp 

. ren year yr_temp

. gen year = by_temp -2
(12,933 missing values generated)

. merge m:1 prov year using "$path2/fines_use", keepusing(fine) nogen
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                     2,199,684
        from master                 2,199,596  
        from using                         88  

    matched                         3,909,661  
    -----------------------------------------

. replace fine = 0 if year < 1979
(2,186,663 real changes made)

. ren fine fine_2

. replace year = by_temp +1
(6,096,412 real changes made, 88 to missing)

. merge m:1 prov year using "$path2/fines_use", keepusing(fine) nogen
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                     1,471,878
        from master                 1,471,847  
        from using                         31  

    matched                         4,637,498  
    -----------------------------------------

. replace fine = 0 if year < 1979
(1,454,086 real changes made)

. ren fine fine_1 

. replace year = by_temp +1
(31 real changes made, 31 to missing)

. merge m:1 prov year using "$path2/fines_use", keepusing(fine) nogen
(label provcnlbl already defined)

    Result                           # of obs.
    -----------------------------------------
    not matched                     1,471,909
        from master                 1,471,878  
        from using                         31  

    matched                         4,637,498  
    -----------------------------------------

. replace fine = 0 if year < 1979
(1,454,086 real changes made)

. ren fine fine_0 

. drop year 

. ren yr_temp year 

. ren by_temp birth_year 

. egen fine = rowmean( fine_1 fine_0)
(17761 missing values generated)

. keep if max_age <= 16
(359,805 observations deleted)

. drop prov

. ren prov_temp prov 

. 
. gen high_order = max_order >= 2 

. replace rural = hktype == 1 if year >= 1990
(706,099 real changes made)

. replace rural = urban == 0 if year == 1982
(0 real changes made)

. 
. replace educ = . if age <= 6
(380,177 real changes made, 380,177 to missing)

. gen girl = sex == 2 

. 
. recode order (2/20 = 2), gen(b_order)
(801513 differences between order and b_order)

. gen han_hh = h_m_han == 1 & h_f_han ==1

. gen non_han_hh = h_m_han == 0 & h_f_han ==0

. 
. cap drop elig_edu

. gen elig_edu = 0 if age >= 7
(2,587,952 missing values generated)

. replace elig_edu = 1 if educ >= 2 & age >= 7 & age < 12 
(1,801,726 real changes made)

. replace elig_edu = 1 if educ >= 3 & age >= 12 & age < 15
(376,979 real changes made)

. replace elig_edu = 1 if educ >= 4 & age >= 15
(53,265 real changes made)

. 
. cap drop illiter  liter junior senior

. gen illiter = educ == 1  if age >= 7
(2,587,952 missing values generated)

. gen liter = educ >= 2 if age >= 7
(2,587,952 missing values generated)

. gen junior = educ >= 3 if age >= 7
(2,587,952 missing values generated)

. gen senior = educ >= 4  if age >= 7
(2,587,952 missing values generated)

. 
. 
. 
. gen wt = 1 

. replace wt = 4 if year == 2005 
(215,266 real changes made)

. 
. save "$path2/child_edu",replace 
file /Users/Wei/Dropbox/Fertility/Workingdata/child_edu.dta saved

. 
. log close
      name:  <unnamed>
       log:  /Users/Wei/Dropbox/Fertility/Results/census_data.log
  log type:  text
 closed on:  21 Jan 2020, 10:19:05
-------------------------------------------------------------------------------------------------
